import 'package:get/get.dart';
import 'package:share_fit/app/controllers/base/base_controller.dart';
import 'package:share_fit/app/ute/uteped_const.dart';

import 'pressure_state.dart';

class PressureLogic extends BaseController {
  final PressureState state = PressureState();
  static const methodSetAutoStress = "setAutoStress";

  void setPressureEnable(bool value) {
    showLoading();
    state.pressureEnable = value;
    bRemoteReqAsync(methodSetAutoStress, {UTEPedConst.keyEnable: value})
        .then((success) => _onSetPressureEnable(success, value));
  }

  void _onSetPressureEnable(success, value) {
    cancelLoading();
    if (success) {
      save(methodSetAutoStress, value);
    }
    else {
      state.pressureEnable = !value;
    }
    update(['pressure_switch']);
  }

  @override
  String getRemotePath() {
    return UTEPedConst.pathDeviceOptions;
  }

  @override
  String getStoragePath() {
    return UTEPedConst.pathDevice;
  }

  @override
  void initState() {
    state.pressureEnable = read(methodSetAutoStress, defaultValue: false);
  }

  @override
  void onRemoteEvent(event, method) {
    // TODO: implement onRemoteEvent
  }
}
